/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package MOs;

import MOs.strategy.finiteDifference.DAO.*;
import MOs.strategy.finiteDifference.BLO.*;
import MOs.strategy.finiteDifference.bean.*;

import controller.java.Microorganism;
import controller.java.Movement;
import controller.java.Petri;
import controller.java.Position;
import data.java.Defs;

import javax.swing.*;
import java.awt.*;

/**
 *
 * @author Erick Rubio Mendoza
 */
public class finiteDifference extends Microorganism  {
    private finiteDifferenceMO oFDMO;
    private finiteDifferenceEnviroment oFDEnviroment;
    private finiteDifferenceDiferentialMove oFDDiferentialMove;
    
    private Graphics2D bufferPetri;
    private Image petri;
    private int PETRI_SIZE;
        
    public void move(Movement mov) {
        initializer();
        try
        {
            mov.dx = oFDDiferentialMove.getDx();
            mov.dy = oFDDiferentialMove.getDy();
            
            //System.out.println("dx:"+oFDDiferentialMove.getDx()+", dy:" + oFDDiferentialMove.getDy());
            
            
            return;
        }catch(NullPointerException ignored){ }
        
    }

    public boolean mitosis() {      
        finiteDifferenceStrategyBLO oFDStrategyBLO = new finiteDifferenceStrategyBLO();
        //&& oFDStrategyBLO.determineMitosis(this.oFDMO)
        if ("VIP".equals(this.oFDMO.getType()) && oFDStrategyBLO.determineMitosis(this.oFDMO))
        {
            return true;
        }
        else 
        {
            return false;
        }
       
    }

    public String getName() {
        return "finiteDifference_java";
    }

    public String getAuthor() {
        return "ErickRubioMendoza";
    }

    public String getAffiliation() {
        return "Lima-Peru";
    }    
    
    public void initializer()
    {
       //Analysisi MO
       finiteDifferenceMO oFDMO = new finiteDifferenceMO();
       oFDMO.setX(pos.x);
       oFDMO.setY(pos.y);
       oFDMO.setMode(0);
       
       finiteDifferenceMODAO oFDMODAO = new finiteDifferenceMODAO();
       oFDMODAO.MOAnalysis(oFDMO);
       if (oFDMO.getMode()==1)
       {
           if (oFDMO.getX()!=oFDMO.getWeakEnemy().getX() || oFDMO.getY()!=oFDMO.getWeakEnemy().getY())
           {
               System.out.println("debe atacar a un enemigo");
           }                
       }
       
       
       //Analysis Enviroment
       finiteDifferenceEnviroment oFDEnviroment = new finiteDifferenceEnviroment();              
       finiteDifferenceEnviromentDAO oFDEnviromentDAO = new finiteDifferenceEnviromentDAO();
       
       oFDEnviromentDAO.enviromentAnalysis(oFDMO, oFDEnviroment);              
       
       //Strategy
       finiteDifferenceStrategyBLO oFDStrategyBLO = new finiteDifferenceStrategyBLO();
       oFDStrategyBLO.determineTypeMO(oFDMO, oFDEnviroment);
       
  
       
       finiteDifferenceDiferentialMove oFDDiferentialMove = new finiteDifferenceDiferentialMove();
       
       oFDStrategyBLO.determineVectorAttack(oFDEnviroment, oFDMO, oFDDiferentialMove);
       
       
       
       if (oFDDiferentialMove.getDx()==0 && oFDDiferentialMove.getDy()==0)
       {
           oFDStrategyBLO.determineVectorMove(oFDEnviroment, oFDMO, oFDDiferentialMove);
           System.out.println("moviendo: (" + oFDMO.getX() + "," + oFDMO.getY() + ") ---> ("+oFDDiferentialMove.getDx()+"," + oFDDiferentialMove.getDy()+")");
       }
       else
       {
           System.out.println("atacando: (" + oFDMO.getX() + "," + oFDMO.getY() + ") ---> ("+oFDDiferentialMove.getDx()+"," + oFDDiferentialMove.getDy()+")");
       }        
       
       
       this.oFDMO = oFDMO;
       this.oFDEnviroment = oFDEnviroment;
       this.oFDDiferentialMove = oFDDiferentialMove;
    }
    

}
